/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import ejb.GameUser;
import ejb.UserFacadeRemote;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author automne
 */
public class UserLogin {
    
    InitialContext context;
    UserFacadeRemote facade;

    public UserLogin(String mappedName) {
        System.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
        try {
            context = new InitialContext();
            facade = (UserFacadeRemote) context.lookup(mappedName);
        } catch (NamingException ex) {
            Logger.getLogger(UserLogin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void create(String username, String password, String realName) {
        GameUser newUser = new GameUser();
        newUser.setId(username);
        newUser.setPassword(password);
        newUser.setRealName(realName);
        facade.create(newUser);
//        String s = "";
//        List<Wordlist> pp = facade.findAll();
//        for(Wordlist p : facade.findAll())
//        {
//            s += "Person: " + p.getId() + "\n";
//            System.out.println(s);
//        }
    }



    public boolean find(String username, String password) {
        boolean isMatch = false;
        GameUser user = facade.find(username.toLowerCase());
        if (user != null && user.getPassword().equals(password) == true) {
            isMatch = true;
        } else {
            isMatch = false;
        }
        return isMatch;
    }
}
